package cn.wolfcode.car.controller;

import cn.wolfcode.car.domain.SystemDictionary;
import cn.wolfcode.car.qo.SystemDictionaryQueryObject;
import cn.wolfcode.car.service.ISystemDictionaryService;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import result.JsonResult;

import java.util.List;

@Controller
@RequestMapping("/systemDictionary")
public class SystemDictionaryController {
    @Autowired
    private ISystemDictionaryService systemDictionaryService;


    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") SystemDictionaryQueryObject qo) {
        PageInfo<SystemDictionary> list = systemDictionaryService.list(qo);
        System.out.println(list);
        model.addAttribute("result", list);
        List<SystemDictionary> systemDictionarys = systemDictionaryService.listAll();
        model.addAttribute("systemDictionarys", systemDictionarys);
        return "systemDictionary/list";
    }

    @PostMapping("/saveOrUpdate")
    public String saveOrUpdate(SystemDictionary systemDictionary) {
        if (systemDictionary.getId() == null) {
            systemDictionaryService.save(systemDictionary);
        } else {
            systemDictionaryService.update(systemDictionary);
        }
        return "redirect:/systemDictionary/list";
    }



    @GetMapping("/delete")
    @ResponseBody
    public JsonResult delete(Long id) {
        systemDictionaryService.delete(id);
        return JsonResult.success(null);
    }
}
